import CommonBaseSchema from '#common/base_schema'

export default class extends CommonBaseSchema {
  protected tableName = 'sales_orders'

  async up() {
    this.schema.createTable(this.tableName, (table) => {
      table.increments()
      table.integer('fk_shop_id').notNullable().unsigned().references('shops.id').comment('店铺ID')

      table
        .integer('fk_source_id')
        .notNullable()
        .unsigned()
        .references('dicts.id')
        .comment('来源ID')

      table.integer('fk_member_id').nullable().unsigned().references('members.id').comment('会员ID')

      table.string('bill_no', 100).unique().index().comment('销售单号')
      table.dateTime('bill_date').comment('销售日期')
      table.string('bill_type', 10).comment('销售类型')
      table.string('customer_name', 50).defaultTo('散客').comment('客户姓名')
      table.tinyint('customer_sex').unsigned().defaultTo(2).comment('客户性别')
      table.string('customer_phone', 11).defaultTo('').comment('客户电话')
      table.integer('actual_price').unsigned().defaultTo(0).comment('实际价格')
      table.integer('actual_pay_price').unsigned().defaultTo(0).comment('实际支付价格')
      table.integer('total_amount').unsigned().defaultTo(0).comment('总金额')
      table.tinyint('status').unsigned().defaultTo(1).comment('状态')
      table.string('memo', 255).defaultTo('').comment('备注')

      this.defineCommonColumns(table)
      table.comment('销售单表')
    })
  }

  async down() {
    this.schema.dropTable(this.tableName)
  }
}
